package org.balthie.demo.sum.misc.direct;

import java.lang.reflect.Field;

public class DirectByteBufferPrinter
{
    public static void printBits()
    {
        try
        {
            Class cls = Class.forName("java.nio.Bits");
            Field[] fields = cls.getDeclaredFields();
            Field f = null;
            StringBuilder s = new StringBuilder();
            s.append("[");
            for(int i = 0; i < fields.length; i++)
            {
                f = fields[i];
                if(f.getName().equalsIgnoreCase("maxMemory")
                        || f.getName().equalsIgnoreCase("reservedMemory") || f.getName().equalsIgnoreCase("totalCapacity")
                        || f.getName().equalsIgnoreCase("count"))
                {
                    f.setAccessible(true);
                    s.append(f.getName()).append(" : ").append(f.get(null));
                    if(i < fields.length - 1)
                        s.append(",");
                }
            }
            s.append("]");
            System.out.println(s.toString());
        }
        catch (ClassNotFoundException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (SecurityException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (IllegalArgumentException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (IllegalAccessException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
